﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using rbac.Contracts.DTO.Input;
using rbac.Contracts.DTO.Output;
using rbac.Contracts.Interface;
using rbac.Domain.Entity;

namespace rbac.API.Controllers
{
    /// <summary>
    /// 角色权限
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class RolePermissionController : ControllerBase
    {
        private readonly IRolePerMissionService _rolePerMissionService;

        public RolePermissionController(IRolePerMissionService rolePerMissionService)
        {
            _rolePerMissionService = rolePerMissionService;
        }
        /// <summary>
        /// 分配权限
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public Results<int> DistributeRolePermission([FromBody] DistributeRolePermissionsInput input)
        {
            return Results<int>.DataResult(_rolePerMissionService.DistributeRolePermission(input));
        }
        /// <summary>
        /// 获取角色获取权限列表
        /// </summary>
        /// <param name="roleId"></param>
        /// <returns></returns>
        [HttpGet]
        public Results<List<PermissionDto>> GetPermissionByRoleId(int roleId)
        {
            return Results<List<PermissionDto>>.DataResult(_rolePerMissionService.GetPermissionByRoleId(roleId));
           
        }

    }
}
